//
//  SecurityAttendancePanel.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/5/19.
//

import Foundation
import UIKit

class SecurityAttendancePanel: CornerView {
    init() {
        super.init(frame: .zero)
        backgroundColor = UIColor.white
        setupUI()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        corners = SBRectCorner(topLeft: 8, topRight:8)
        backgroundColor = .white

        addSubview(titleView)
        titleView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.top.equalToSuperview().offset(20)
            make.height.equalTo(18)
            make.bottom.equalToSuperview().offset(-20)
        }
    }

    lazy var titleView: SectionTitleView = {
        let view = SectionTitleView(withStyle: SectionTitleStyleEnum.Style2, title: "当日考勤记录")
        return view
    }()
}

class SecurityAttendanceCell: UITableViewCell {
    let nameL = UILabel()
    let signinL = UILabel()
    let zgscL = UILabel()
    let signoutL = UILabel()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func reload(withData modal: BaglSignInfoModel?) {
        nameL.text = modal?.nickName
        zgscL.text = "在岗时长：\(modal?.zggs ?? "0")"
        signinL.text = "签到：\(modal?.qdsj ?? "-")"
        signoutL.text = "签退：\(modal?.qtsj ?? "-")"
    }
    
    func setupUI() {
        let width = (ScreenWidth - 50) / 2.0

        nameL.font = UIFont.systemFont(ofSize: 17)
        nameL.textColor = .hex("#333333")
        addSubview(nameL)
        nameL.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(15)
            make.left.equalToSuperview().offset(10)
            make.width.equalTo(width)
        }
        
        signinL.font = UIFont.systemFont(ofSize: 14)
        signinL.textColor = .hex("#BABABA")
        signinL.adjustsFontSizeToFitWidth = true
        addSubview(signinL)
        signinL.snp.makeConstraints { make in
            make.top.equalTo(nameL.snp.bottom).offset(6)
            make.left.equalTo(nameL.snp.left)
            make.width.equalTo(width)
        }
        
        zgscL.font = UIFont.systemFont(ofSize: 14)
        zgscL.textColor = .hex("#ACACAC")
        zgscL.textAlignment = .right
        addSubview(zgscL)
        zgscL.snp.makeConstraints { make in
            make.top.equalTo(nameL.snp.top)
            make.right.equalToSuperview().offset(-10)
            make.width.equalTo(width)
        }
        
        signoutL.font = UIFont.systemFont(ofSize: 14)
        signoutL.textColor = .hex("#ACACAC")
        signoutL.textAlignment = .right
        signoutL.adjustsFontSizeToFitWidth = true
        addSubview(signoutL)
        signoutL.snp.makeConstraints { make in
            make.centerY.equalTo(signinL.snp.centerY)
            make.width.equalTo(width)
            make.right.equalTo(zgscL.snp.right)
        }
    }
}
